package com.hemerasolutions.v2trainer.model.schedule;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.goals.Competition;
import com.hemerasolutions.v2trainer.model.goals.Goal;

@Entity
public class Cycle extends BaseModel implements Comparable<Cycle> {
	 
	private static final long serialVersionUID = 1L;

    @Column(length = 50)
	private String name;

    @Column(length = 180)
    private String description;
    
    @Column
	private int begWeek;
	
    @Column
    private int endWeek;
	
    @OneToMany
    private List<Competition> competition;
    
    @OneToMany
    private List<Goal> goals;
	
    @OneToMany(mappedBy="upperCycle", cascade =  CascadeType.ALL, fetch= FetchType.LAZY)
	private List<Cycle> subCycles;

    @ManyToOne
    private Cycle upperCycle;
    
    @OneToMany
	private List<DaySchedule> daySchedules;

	
	public Cycle() {
		super();		
		this.subCycles = new ArrayList<Cycle>();

	}

	public Cycle(String name) {
		super();
		this.subCycles = new ArrayList<Cycle>();
		this.name = name;
	}

	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}



	public int getBegWeek() {
		return begWeek;
	}

	public int getEndWeek() {
		return endWeek;
	}

	public List<Competition> getCompetition() {
		return competition;
	}

	public List<Goal> getGoals() {
		return goals;
	}

	public List<Cycle> getSubCycles() {
		return subCycles;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}



	public void setBegWeek(int begWeek) {
		this.begWeek = begWeek;
	}



	public void setEndWeek(int endWeek) {
		this.endWeek = endWeek;
	}

	public void setCompetition(List<Competition> competition) {
		this.competition = competition;
	}

	public void setGoals(List<Goal> goals) {
		this.goals = goals;
	}

	public void setSubCycles(List<Cycle> cycles) {
		this.subCycles = cycles;
	}

	@Override
	public int compareTo(Cycle cycle) {

		if(this.getBegWeek() > cycle.getBegWeek()){
			return -1;
		}else{
			return 1;
		}
	}
	 
}
 
